#include <QLabel>
#include <QFileInfo>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTextEdit>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QTime>
#include <QIcon>

#include "tabwidgets.h"

GeneralTab::GeneralTab(QWidget *parent)
    : QDialog(parent)
{
    textEdit = new QTextEdit(this);
    textEdit->setText("");
    textEdit->setFrameStyle(QFrame::NoFrame | QFrame::Plain);
    textEdit->setReadOnly(true);
    mainLayout = new QVBoxLayout;
    mainLayout->addWidget(textEdit);
    setLayout(mainLayout);
}

void GeneralTab::setGeneralTab(const QString &fileName,const int &recvId)
{
    textEdit->clear();
    QFileInfo fileInfo(fileName);
    textEdit->append("<span style=\"color: rgb(0, 51, 204);\
                      font-weight: bold;\">File path:</span>");
    textEdit->append(fileInfo.absoluteFilePath());
    textEdit->append("<span style=\"color: rgb(0, 51, 204); \
                     font-weight: bold;\">File created time:</span>");
    textEdit->append(fileInfo.created().toString());
    textEdit->append("<span style=\"color: rgb(0, 51, 204); \
                     font-weight: bold;\">Last recieverId:</span>");
    textEdit->append(QString::number(recvId));
}

logTab::logTab(QWidget *parent)
    :QDialog(parent)
{
    logView = new QTreeWidget(this);

    QStringList headers;
    headers<<"Time"<<"Message";
    logView->setHeaderLabels(headers);
    logView->setSelectionBehavior(QAbstractItemView::SelectRows);
    logView->setAlternatingRowColors(true);
    logView->setRootIsDecorated(false);
    logView->setContentsMargins(0,0,0,0);

    mainLayout = new QHBoxLayout;
    mainLayout->addWidget(logView);
    setLayout(mainLayout);
}

void logTab::setlogTab(const QTime &logTime, const QString &logMessage)
{
    item = new QTreeWidgetItem(logView);
    item->setBackgroundColor(0,"#98FB98");
    item->setBackgroundColor(1,"#98FB98");
    item->setText(0,logTime.toString("hh:mm:ss"));
    item->setText(1,logMessage);
}

void logTab::clearLogTab()
{
    logView->clear();
}
